package com.zzy.face.service.impl;

import com.zzy.face.dao.StudentDao;
import com.zzy.face.dto.StudentInfo;
import com.zzy.face.model.Student;
import com.zzy.face.model.Teacher;
import com.zzy.face.service.StudentService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @Author 朱泽玉
 * @Create 2022/1/30 17:12
 * @Description
 * @Modified By:
 */
@Service
public class StudentServiceImpl implements StudentService {
    final StudentDao studentDao;

    public StudentServiceImpl(StudentDao studentDao) {
        this.studentDao = studentDao;
    }

    @Override
    public void save(Student student) {
        studentDao.save(student);
    }

    @Override
    public void del(Long uid) {
        studentDao.delete(Objects.requireNonNull(studentDao.findById(uid).orElse(null)));
    }

    @Override
    public Student findById(Long uid) {
        return studentDao.getOne(uid);
    }

    @Override
    public StudentInfo findStudentInfo(Long uid) {
        return studentDao.findStudentInfo(uid);
    }

    @Override
    public List<StudentInfo> findStudentsInfo() {
        return studentDao.findStudentsInfo();
    }

    @Override
    public Student getStudentByMobile(String mobile) {
        return studentDao.findById(Long.valueOf(mobile)).orElse(null);
    }

    @Override
    public  List<StudentInfo> findStudentInfosInTeacher(Long uid) {
        return studentDao.findStudentInfosInTeacher(uid);
    }

    @Override
    public long findMyTeacher(Long uid) {
        return studentDao.getOne(uid).getTeacherId();
    }
}
